package com.kjc.demo.basic.controller;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;

import org.springframework.amqp.core.AmqpTemplate;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import com.kjc.demo.basic.service.RabbitService;

import lombok.extern.slf4j.Slf4j;

@RestController
@RequestMapping(value = "/rabbitmq")
@Slf4j
public class RabbitMqTestDemo {
	
	@Autowired
	private RabbitService rabbitService;
	
	@Resource
    private AmqpTemplate template;
	
	@GetMapping("/send")
	public String setredisvalue(HttpServletRequest request) {
		String key = request.getParameter("queue");
		String value = request.getParameter("message");
		log.info("redis");
		rabbitService.send(key, value);//Redis赋值
		return "success";
	}
	
	@GetMapping("/sendTopics")
	public String sendTopics(HttpServletRequest request) {
		String key = request.getParameter("queue");
		String value = request.getParameter("message");
		log.info("topic1");
		rabbitService.send1();//Redis赋值
		return "success";
	}
	
	@GetMapping("/sendTopic")
	public String sendTopic(HttpServletRequest request) {
		String key = request.getParameter("queue");
		String value = request.getParameter("message");
		log.info("topic1");
		rabbitService.send2();//Redis赋值
		return "success";
	}
	
	@GetMapping("/fanout")
	public void send() {
		String context = "hi, fanout msg ";
		System.out.println("Sender : " + context);
//		this.rabbitService.send("fanoutExchange", context);
		this.template.convertAndSend("fanoutExchange","", context);
	}
	
}
